/*
 * SocketService.h
 *
 *  Created on: Nov 12, 2012
 *      Author: root
 */

#ifndef zeus_SOCKETSERVICE_H_
#define zeus_SOCKETSERVICE_H_

#include "IoService.h"

#include "Operation.hpp"

namespace zeus
{

class SocketService
{
private:

	IoService & _io_service;

public:
	SocketService(IoService & io_service);
	virtual ~SocketService();

public:

	template<typename Descriptor,typename SocketType,typename CompleteHandler>
	void start_accept_op(Descriptor descriptor,SocketType & peer,const CompleteHandler & handler)
	{
		Operation * operation = new AcceptOperation<Descriptor,SocketType,CompleteHandler>(descriptor,peer,handler);

		_io_service.read_op(descriptor,operation);
	}

	template<typename Descriptor,typename BufferType,typename CompleteHandler>
	void start_read_op(Descriptor descriptor,BufferType & buff,const CompleteHandler & handler)
	{
		Operation * operation = new ReadOperation<Descriptor,BufferType,CompleteHandler>(descriptor,buff,handler);

		_io_service.read_op(descriptor,operation);
	}

	template<typename Descriptor,typename BufferType,typename CompleteHandler>
	void start_write_op(Descriptor descriptor,BufferType & buff,const CompleteHandler & handler)
	{
		Operation * operation = new WriteOperation<Descriptor,BufferType,CompleteHandler>(descriptor,buff,handler);

		_io_service.read_op(descriptor,operation);
	}
};

} /* namespace zeus */
#endif /* zeus_SOCKETSERVICE_H_ */
